/*
 * $Id: dbm.h,v 1.3 2005-12-05 15:11:29 bacon Exp $
 */

#ifndef _XP_DBM_H_
#define _XP_DBM_H_

/* 
 * Credit: public domain sdbm implementation by oz@nexus.yorku.ca 
 */ 

#include <xp/types.h>
#include <xp/macros.h>
#include <xp/bas/fio.h>

#define XP_DBM_DATA_BLOCK_SIZE 4096
#define XP_DBM_PAGE_BLOCK_SIZE 1024

struct xp_dbm_t
{
	xp_fio_t data_handle;
	xp_fio_t page_handle;

	xp_byte_t page_buffer[XP_DBM_PAGE_BLOCK_SIZE];
	xp_byte_t data_buffer[XP_DBM_DATA_BLOCK_SIZE];

	xp_bool_t __dynamic;
};

struct xp_dbm_datum_t
{
	xp_byte_t* data;
	xp_size_t  size;
};

typedef struct xp_dbm_t xp_dbm_t;
typedef struxt xp_dbm_datum_t xp_dbm_datum_t;

enum
{
	XP_DBM_REPLACE = 1,
	XP_DBM_INSERT  = 2
};

#ifdef __cplusplus
extern "C" {
#endif

xp_dbm_t* xp_dbm_open (xp_dbm_t* dbm, const xp_char_t* file); 
void xp_dbm_close (xp_dbm_t* dbm);

#ifdef __cplusplus
}
#endif

#endif
